// -*-C++-*-

#pragma once
#ifndef API_SMP_UTILS_HEADER
#define API_SMP_UTILS_HEADER

// Intel 3a  8.10.6.7: 128-byte boundary
typedef unsigned int spinlock_t __attribute__((aligned(128)));

struct smp_spinlock
{
  void lock();
  void unlock();

private:
  volatile spinlock_t m_value = 0;
};

struct smp_barrier
{
  void increment() noexcept
  {
    __sync_fetch_and_add(&val, 1);
  }

  void spin_wait(int max) noexcept;

  void reset(int val = 0) noexcept
  {
    __sync_synchronize();
    this->val = val;
  }

private:
  volatile int val = 0;
};

#endif // hdr
